import axios from 'axios'
export default {
    // 先记得开命名空间
    namespaced: true,
    state () {
        return {
            // 保存购物车数据
            cartList: []
        }
    },
    // 唯一修改state的是mutations
    mutations: {
        setCartList (state, list) {
            state.cartList = list
        }
    },

    actions: {
        async reqCartList (ctx) {

            // 发请求
            const res = await axios({
                url: 'http://localhost:3000/cart'
            })

            ctx.commit('setCartList', res.data)
        }
    }
}